from flask import Blueprint, request, jsonify
import json
from utils.db import db1
from view.compan import get_data

bp_work = Blueprint('work', __name__)


@bp_work.route('/work', methods=['POST', 'GET'])
def work():
    if request.method == 'POST':
        data = get_data()
        print(data['params'])
        sql = 'insert into yewu(name,params) values("%s","%s")' % (data['name'], json.loads(data['params']))
        db1.update(sql)
        return jsonify({'code': 200})
    elif request.method == 'GET':
        sql = 'select * from yewu'
        res = db1.findall(sql)
        list = json.loads(res['params'])
        print(list)
        return jsonify({'code': 200, 'list': res})
